import {ADDCOUNTER,ADDCARTLIST} from './mutations-types'
export default{
    addCart(context,payload){
      return new Promise((resolve,reject)=>{
            const oldCount = context.state.carList.find(item=>item.iid === payload.iid )
            if (oldCount) {
                // oldCount.count +=1
                //此种写法方便跟踪
                context.commit(ADDCOUNTER,oldCount)
                resolve('商品数量+1')
            }else{
                payload.count=1
                context.commit(ADDCARTLIST,payload)
                resolve('添加购物车')
                // context.state.carList.push(payload)

            }
            })
        
      }

}